package sum;

// Runnable描述任务，计算1+2+3+...+100
class Result{
    public int sum = 0;
    public Object lock = new Object();
}
public class RunnableSum {
    public static void main(String[] args) throws InterruptedException {
        Result result = new Result();

        Thread t = new Thread(){
            @Override
            public void run(){
                int sum = 0;
                for (int i = 0; i <= 100; i++) {
                    sum+=i;
                }
                synchronized (result.lock){
                    result.sum = sum;
                    result.lock.notify();
                }
            }
        };

        t.start();
        synchronized (result.lock){
            if (result.sum == 0){
                result.lock.wait();
            }
        }
        System.out.println(result.sum);
    }
}
